<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
		<template #nickname="{ record }">
		  <span class="arco-auto-tooltip arco-table-td-content">
		    <span class="arco-auto-tooltip-content">
		      <!-- 新增一个容器用于图片和商品名称并排显示 -->
		      <div class="image-name-container" style="display: flex; align-items: center;">
		        <img  
		          class="time-info goods-image"  
		          data-v-49576cc5="" 
		          :src="record.avatar" 
		          style="object-fit: cover; cursor: pointer; width: 80px; height: 80px; border-radius: 50%; margin-right: 10px;"
		        >
		        <span class="time-info goods-name">{{record.nickname}}</span>
		      </div>
		    </span>
		  </span>
		</template>
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="4">
          <a-form-item label="用户昵称" field="nickname">
            <a-input v-model="searchForm.nickname" placeholder="请输入用户昵称" />
          </a-form-item>
        </a-col>
		<a-col :span="4">
		  <a-form-item label="手机号" field="phone">
		    <a-input v-model="searchForm.phone" placeholder="请输入手机号" />
		  </a-form-item>
		</a-col>
        <a-col :span="8">
          <a-form-item label="注册时间" field="register_time">
            <a-range-picker v-model="searchForm.register_time" :show-time="true" mode="date" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="最后登录时间" field="last_login_time">
            <a-range-picker v-model="searchForm.last_login_time" :show-time="true" mode="date" />
          </a-form-item>
        </a-col>

      </template>
	  <template #operationAfterExtend="{ record }">
	    <a-link @click="openDetail(record)"   v-auth="['/EbProductLogs/logs/index']"> <icon-plus /> 供需日志 </a-link>
	  </template>

      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import api from '../api/user'
import { useRouter } from 'vue-router'

const router = useRouter()

// 添加 openDetail 方法
const openDetail = (record) => {
  router.push({
    path: '/EbProductLogs/logs',
    query: { user_id: record.user_id }
  })
}

// 引用定义
const crudRef = ref()
const editRef = ref()

// 搜索表单
const searchForm = ref({
  nickname: '',
  register_time: [],
  last_login_time: [],
  real_name: '',
  phone: '',
})


// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  pk: 'user_id',
  operationColumnWidth:200,
  // recycleApi: api.getRecyclePageList,
  rowSelection: { showCheckedAll: true },
  add: {
    show: false,
    auth: ['/WechatUser/EbWechatUser/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: true,
	text:'设置权重',
    auth: ['/WechatUser/EbWechatUser/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: false,
	
    auth: ['/WechatUser/EbWechatUser/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
    realAuth: ['/WechatUser/EbWechatUser/realDestroy'],
    realFunc: async (params) => {
      const resp = await api.realDestroy(params)
      if (resp.code === 200) {
        Message.success(`销毁成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  recovery: {
    show: false,
    auth: ['/WechatUser/EbWechatUser/recovery'],
    func: async (params) => {
      const resp = await api.recovery(params)
      if (resp.code === 200) {
        Message.success(`恢复成功！`)
        crudRef.value?.refresh()
      }
    },
  },
   export: { show: true, url: '/WechatUser/EbWechatUser/export', auth: ['/WechatUser/EbWechatUser/export'] },
  
})

// SaTable 列配置
const columns = reactive([

  { title: '用户信息', dataIndex: 'nickname', width: 180 },
  { title: '手机号', dataIndex: 'phone', width: 180 },
  { title: '供应权重', dataIndex: 'supply_weight', width: 180 },
  { title: '需求权重', dataIndex: 'requirement_weight', width: 180 },
  { title: '浏览权重', dataIndex: 'browsing_weight', width: 180 },
  { title: '收藏权重', dataIndex: 'collection_weight', width: 180 },
  { title: '对接权重', dataIndex: 'docking_eight', width: 180 },
  { title: '注册时间', dataIndex: 'register_time', width: 180 },
  { title: '最后登录时间', dataIndex: 'last_login_time', width: 180 },
])

// 页面数据初始化
const initPage = async () => {}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
